package library.and.xps.com.step.view.activity;

import android.view.View;
import android.widget.TextView;

import com.zhy.autolayout.AutoRelativeLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import library.and.xps.com.step.EventBusCommond;
import library.and.xps.com.step.R;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.view.base.BaseActivity;
import library.and.xps.com.step.view.fragment.PersonChallengeFragment;

public class PersonChallengeActivity extends BaseActivity {
    AutoRelativeLayout ationbar_al;
    PersonChallengeFragment personChallengeFragment;

    @Override
    protected int getLayout() {
        return R.layout.activity_team_challenge;
    }

    @Override
    protected void setData() {
        personChallengeFragment = new PersonChallengeFragment();
        CommonUtils.replaceFragment(R.id.container, personChallengeFragment, getSupportFragmentManager());
    }

    @Override
    protected void init() {
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);
        ((TextView) r2v(R.id.actionbar_tv_title)).setText("个人挑战");
        ationbar_al = r2v(R.id.actionbar_al);
        r2v(R.id.actionbar_iv_back).setOnClickListener(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveEvent(String param) {
        if (param.equals(EventBusCommond.FREASH_PERSON_CHALLENGE))
            personChallengeFragment.onRefresh();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().unregister(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.actionbar_iv_back:
                finish();
                break;
        }
    }

}
